/**
 * 系统设置权限设置管理员
 */
import $_fn from '~plugins'
export default ['$scope','$rootScope','$location','$ui','http',function($scope,$rootScope,$location,$ui,http) {
  $scope.$_fn = $_fn
    $scope.tabMenu = $_fn.getCurrMenu($location.path())
    console.log($scope.tabMenu)
    $scope.subMenu = $scope.tabMenu.children[0].children
    console.log($location.path())
	console.log('系统设置权限设置管理员控制器')
	//初始化参数
	$scope.params={
		pageNum:1,//分页
		locked:-1,//状态
		roleId:-2,//管理组
		type:-1//时间类型
	}
	//全选
	$scope.quanXuan=function(e,name){
        var _checked = $(':checkbox[name=' + name + ']')
        if($(e.target).prop('checked')){
            _checked.each(function(){
                if(!$(this).attr('disabled')) {
                    $(this).prop('checked', true)
                }
            })
        }else{
            _checked.each(function(){
                // $(this).removeAttr('checked')
                if(!$(this).attr('disabled')){
                   $(this).prop('checked','')
                }
            })
        }
    }
	//批量操作
	$scope.ids1=[]
	$scope.piLiang=function(path,name){
		console.log('开始批量炒作')
		var _checked = $(':checkbox[name=' + name + ']')
		console.log(_checked)
		for(var i=0; i<_checked.length; i++){
			if(_checked[i].checked){
				$scope.ids1.push($(_checked[i]).attr('ids'))
			}
		}
		console.log($scope.ids1)
		if($scope.ids1.length<1){
			$ui.toast({
				text:'请选择管理员',
				type:'warning'
			})
		}else{
			$scope.operation(path,$scope.ids1.join(','))
		}
		
	}
	/*$scope.quanXuan=function(className){
		
		$('.'+className).attr('')
	}*/
	$scope.name4=-2
	$scope.getDada=function(page, params){
		http.post('selectPageAdminList.do',params,function (data) {
			if(data.errcode==1){
				console.log(data);
				$scope.data1=data.data.AdminList
				$scope.dataList=data.data.AdminList.list;
				$scope.roles=data.data.roles;
				console.log("qqq:",$scope.roles)
				$scope.$apply()
			}else{
				$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
			}
        },function(_data){
            console.log(_data);//报错
        })
	}
	$scope.parms2={}//用来传参
	//添加管理员
	$scope.operation = function (path,id,name) {
        var _path = path.split('@')
        console.log(_path)
        if(_path[0] == 'link'){
            $state.go(_path[1],{id:id,ids:2})
        }
        if(_path[0] == 'alert'){
        	//$scope.parms2.id=id
        	console.log(id)
        	console.log(_path[1])
            $ui.modal({content:"<"+_path[1]+" id='"+id+"'name='"+name+"'></"+_path[1]+">",title:$scope.parms2})
        }
    }
	//搜索
  $scope.searchHandle = function () {
    if($scope.params.keyword && $scope.params.type==-1){
      $scope.err.type = true
      $scope.errorToast('左侧字段没有选择')
      return
    }
    $location.search($scope.params)
    $scope.getDada(1,$scope.params)
  }
	$scope.getDada(1, $scope.params)
}]
